function [ObjectsByFrame] =  ObtainObjects(parameters,blankflag)
ON=parameters.ON;
maskfilenames=parameters.maskfilenames;
fluorfilenames=parameters.fluorfilenames;

nfiles=size(maskfilenames, 1);
ObjectsByFrame = cell([nfiles, 1]);



parfor i=1:nfiles
%for i=1:5
    ['Object loop, file: ' num2str(i) ' ' datestr(now)]
    %read mask files
    mask=~imread(maskfilenames{i},'tif');
    CurrentObjects = regionprops(bwconncomp(mask,4),'Area','Centroid','Eccentricity','Orientation','PixelIdxList');

    FluorImages = cell([parameters.numcolors, 1]);
    
    %determine if there are fluorescent images for this time step, note
    %this function assumes there are blank images at other time points
    if(mod(i-1,parameters.step) == 0)
        for cn=1:parameters.numcolors
        
            %Determine if there are blank images present in the
            %fluorescence channel (sometimes the microscope software saves
            %these when fluor not sampled with phase).  If yes then there
            %are an equal number of phase and fluor images and they can be
            %scrolled through normally.  If no then there are less fluor
            %then phase and this needs to be taken into account when
            %indexing
            if(blankflag)
                FluorImages{cn} = imread(fluorfilenames{cn, i},'tif');
            else
                FluorImages{cn} = imread(fluorfilenames{cn, ((i-1)/parameters.step)+1},'tif');
            end
        end
    end    
    
    %['End load colors, file: ' num2str(i)]
    for j=1:length(CurrentObjects)

        %CurrentObjects(j).Number=uint16(j);  
        ObjectsByFrame{i}(j,ON.Area)=CurrentObjects(j).Area;
        ObjectsByFrame{i}(j,ON.CentroidX)=CurrentObjects(j).Centroid(1);
        ObjectsByFrame{i}(j,ON.CentroidY)=CurrentObjects(j).Centroid(2);
        ObjectsByFrame{i}(j,ON.Eccentricity)=CurrentObjects(j).Eccentricity;
        ObjectsByFrame{i}(j,ON.Orientation)=CurrentObjects(j).Orientation;
        ObjectsByFrame{i}(j,ON.Number)=j;
        
        for cn=1:parameters.numcolors
            %Images taken in uint16 format, to compute std they must be
            %converted to double
            if(mod(i-1,parameters.step) == 0)
                ObjectsByFrame{i}(j,ON.fluorMean(cn))=mean(double(FluorImages{cn}(CurrentObjects(j).PixelIdxList)));
                ObjectsByFrame{i}(j,ON.fluorStd(cn))=std(double(FluorImages{cn}(CurrentObjects(j).PixelIdxList)));
                ObjectsByFrame{i}(j,ON.fluorMax(cn))=max(double(FluorImages{cn}(CurrentObjects(j).PixelIdxList)));
                prcVals=prctile(double(FluorImages{cn}(CurrentObjects(j).PixelIdxList)),parameters.prcRange);
                ObjectsByFrame{i}(j,ON.fluorPrcRatio(cn))=prcVals(2)/prcVals(1);
            else
                ObjectsByFrame{i}(j,ON.fluorMean(cn))=NaN;
                ObjectsByFrame{i}(j,ON.fluorStd(cn))=NaN;
                ObjectsByFrame{i}(j,ON.fluorMax(cn))=NaN;
                ObjectsByFrame{i}(j,ON.fluorPrcRatio(cn))=NaN;                
            end
        end
    end

    %count=count+1
    %waitbar(count / nfiles,h)
end
